﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ICSharpCode.SharpZipLib.Zip;
using UnityEditor;
using Kylin;

public class RevisionZipUtils {

    static bool ZipVersionSuccess = true;
    static long ZipFilesize;
    static long ZipedSize;

    static void DirectoryFailureHandler(object sender, ICSharpCode.SharpZipLib.Core.ScanFailureEventArgs e)
    {
        Debug.LogError("Zip directoty fail :" + e.Name);
        ZipVersionSuccess = false;
    }

    static void FileFailureHandler(object sender, ICSharpCode.SharpZipLib.Core.ScanFailureEventArgs e)
    {
        Debug.LogError("Zip file fail :" + e.Name);
        ZipVersionSuccess = false;
    }

    static void ProgressHandler(object sender, ICSharpCode.SharpZipLib.Core.ProgressEventArgs e)
    {
        ZipedSize += e.Processed;
        Debug.Log("压缩工作中 ... 已经处理：" + ZipedSize);
        float percent = (float)ZipedSize / ZipFilesize;
    }

    public static void ZipFile(string zipFile, string folder)
    {
        FastZipEvents zipEvent = new FastZipEvents();

        zipEvent.DirectoryFailure = DirectoryFailureHandler;
        zipEvent.FileFailure = FileFailureHandler;
        zipEvent.Progress = ProgressHandler;

        FileUtils.ZipFile(zipFile, folder, zipEvent);
        while (!ZipVersionSuccess)
        {
            ZipVersionSuccess = true;
            FileUtils.ZipFile(zipFile, folder, zipEvent);
        }
    }
}
